package com.eleadmin.order.controller;

import com.eleadmin.common.core.web.*;
import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.order.entity.MaintainFeeAttach;
import com.eleadmin.order.service.MaintainFeeAttachService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 附加费维护
 * @author : Doman
 * @date : 2023-03-28 13:48:23
 * @version ：1.0
 */

@Api(tags = "附加费维护")
@RestController
@RequestMapping("/api/order/maintainFeeAttach")
public class MaintainFeeAttachController extends BaseController {

    @Autowired
    private MaintainFeeAttachService maintainFeeAttachService;

    @PreAuthorize("hasAuthority('order:maintainFeeAttach:list')")
    @ApiOperation("分页查询附加费维护")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, MaintainFeeAttach maintainFeeAttach) throws Exception{
        return maintainFeeAttachService.list(page, maintainFeeAttach, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:maintainFeeAttach:list')")
    @ApiOperation("查询全部附加费维护")
    @GetMapping()
    public JsonResult list(MaintainFeeAttach maintainFeeAttach){
        return maintainFeeAttachService.list(maintainFeeAttach, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:maintainFeeAttach:list')")
    @ApiOperation("返回附加费维护select列表")
    @GetMapping("listSel")
    public JsonResult listSel(MaintainFeeAttach maintainFeeAttach){
        return maintainFeeAttachService.listSel(maintainFeeAttach, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:maintainFeeAttach:list')")
    @ApiOperation("根据id查询附加费维护")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return maintainFeeAttachService.getById(id);
    }


    @PreAuthorize("hasAuthority('order:maintainFeeAttach:save')")
    @OperationLog
    @ApiOperation(value ="添加附加费维护")
    @PostMapping()
    public JsonResult save(@RequestBody MaintainFeeAttach maintainFeeAttach) {
        try {
            return maintainFeeAttachService.save(maintainFeeAttach, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('order:maintainFeeAttach:update')")
    @OperationLog
    @ApiOperation(value ="修改附加费维护")
    @PutMapping()
    public JsonResult update(@RequestBody MaintainFeeAttach maintainFeeAttach) {
        try {
            return maintainFeeAttachService.update(maintainFeeAttach, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:maintainFeeAttach:remove')")
    @OperationLog
    @ApiOperation(value ="删除附加费维护")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") String id) {
        try {
            return maintainFeeAttachService.remove(id, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

}
